package dao

import (
	"github.com/jinzhu/gorm"
	"go-admin/internal/model"
)

func (d *Dao) CreateUserRole(db *gorm.DB, userId string, roleIds []string) error {
	userRole := model.UserRole{}
	return userRole.Create(db, userId, roleIds)
}

func (d *Dao) GetRoleIdsByUserId(userId string) ([]*model.UserRole, error) {
	userRole := model.UserRole{}
	return userRole.GetRoleIdsByUserId(d.Engine, userId)
}

// 根据用户id删除绑定的角色
func (d *Dao) DeleteUserRolesS(db *gorm.DB, userId string) error {
	userRole := model.UserRole{}
	return userRole.Delete(db, userId)
}

// 通过用户名称获取用户角色集合
func (d *Dao) GetRolesByUserName(username string) ([]*model.Role, error) {
	userRole := model.Role{}
	return userRole.GetRolesByUserName(d.Engine, username)
}
